#!/usr/bin/env python
#-*- coding:utf-8 -*-

'''
Created on 2011-12-15

@author: zhangchong
'''



import traceback
import sys
import os
import json
import string
import MySQLdb
import simplejson
import Config
import time
from Tools import connectMySQL
from Tools import getPid




notStatistPid = Config.notStatistPid
StatistResultsDir = Config.StatistResultsDir
SaveLogDir = Config.SaveLogDir



class Static:
    SaveLogDir = SaveLogDir
    save = None
    accessLog = "access"
    statisLog = "statis"
    pidFilter = "all"
    paramFilter = "any"
    uniqueFields = "pid guid"
    vidFile = ""
    def __init__(self, date):
        self.date = date
   

class JsLoader_InitialUuid(Static):
    save = "jsloader_initial_uuid.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    uniqueFields = "pid uuid"
    urlReg = [
            (r"/initial", "" , "jsloader_initial_uuid", "", "", "", "")   ,
    ] 


class JsLoader_Initial(Static):
    save = "jsloader_initial.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    urlReg = [
            (r"/initial", "" , "jsloader_initial", "", "", "", "")   ,
    ] 
    
class JsLoader_InitialGuid(Static):
    save = "jsloader_initial_guid.json";
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "guid=[a-z0-9]{32}"
    urlReg = [
          (r"/initial", "" , "jsloader_initial_guid", "", "", "", "")    
          ]
        
class JsLoader_InitialNoGuid(Static):
    save = "jsloader_initial_noguid.json";
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "!guid=[a-z0-9]{32}"
    uniqueFields = "pid uuid"
    urlReg = [
          (r"/initial", "" , "jsloader_initial_noguid", "", "", "", "")    
          ]    
    
 

class JsLoader_VVDetail(Static):
    save = "jsloader_vv_detail.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    urlReg = [
            (r'/statis/vv\?adapter=ios_m3u8', "" , "adapter=ios_m3u8", "", "", "", ""),
            (r'/statis/vv\?adapter=android_m3u8', "" , "android_m3u8", "", "", "", ""),
            (r'/statis/vv\?adapter=html5_mp4', "" , "html5_mp4", "", "", "", ""),
            (r'/statis/vv\?adapter=html5mp4_download', "" , "html5mp4_download", "", "", "", ""),
            (r'/statis/vv\?adapter=html5mp4_error', "" , "html5mp4_error", "", "", "", ""),
            (r'/statis/vv\?adapter=flash', "" , "flash", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_error', "" , "playurl_error", "", "", "", ""),
            
            (r'/statis/vv\?adapter=playurl_ErrCode400_400', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode400_-100', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode400_-101', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode400_-102', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode400_-104', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode400_-105', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode400_-106', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode400_-998', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode-999', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode-1999', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode-2999', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode-3999', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode-4999', "" , "playurl_ErrCode", "", "", "", ""),
            (r'/statis/vv\?adapter=playurl_ErrCode-5999', "" , "playurl_ErrCode", "", "", "", ""),
            
            (r'/statis/vv\?pid=', "" , "NoAdapterParam", "", "", "", ""),         
    ] 

class JsLoader_VVBegin_AndroidM3u8(Static):
    save = "jsloader_vv_AndroidM3u8.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_AndroidM3u8_VID.txt"
    urlReg = [
            (r'/statis/vv\?adapter=android_m3u8', "" , "android_m3u8", "", "", "", ""),
    ] 

class JsLoader_VVBegin_iOSM3u8(Static):
    save = "jsloader_vv_iOSM3u8.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_iOSM3u8_VID.txt"
    urlReg = [
            (r'/statis/vv\?adapter=ios_m3u8', "" , "ios_m3u8", "", "", "", ""),
    ] 

class JsLoader_VVBegin_Html5Mp4Error(Static):
    save = "jsloader_vv_Html5Mp4Error.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_Html5Mp4Error_VID.txt"
    urlReg = [
            (r'/statis/vv\?adapter=html5mp4_error', "" , "html5mp4_error", "", "", "", ""),
    ] 

class JsLoader_VVBegin_PlayurlError(Static):
    save = "jsloader_vv_PlayurlError.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_PlayurlError_VID.txt"
    urlReg = [
            (r'/statis/vv\?adapter=playurl_error', "" , "playurl_error", "", "", "", ""),
    ] 

class JsLoader_VVBegin_PlayurlErrCode(Static):
    save = "jsloader_vv_PlayurlErrCode.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_PlayurlErrCode_VID.txt"
    urlReg = [
            (r'/statis/vv\?adapter=playurl_ErrCode', "" , "playurl_ErrCode", "", "", "", ""),
    ] 


class JsLoader_VVBegin_PlayurlErrCode400(Static):
    save = "jsloader_vv_PlayurlErrCode400.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_PlayurlErrCode_VID400.txt"
    urlReg = [
            (r'/statis/vv\?adapter=playurl_ErrCode400', "" , "playurl_ErrCode400", "", "", "", ""),
    ] 


class JsLoader_VVBegin_Html5Mp4Error(Static):
    save = "jsloader_vv_Html5Mp4Error.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_Html5Mp4Error_VID.txt"
    urlReg = [
            (r'/statis/vv\?adapter=html5mp4_error', "" , "html5mp4_error", "", "", "", ""),
    ] 

class JsLoader_VVBegin_Html5Mp4Download(Static):
    save = "jsloader_vv_Html5Mp4Download.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_Html5Mp4Download_VID.txt"
    urlReg = [
            (r'/statis/vv\?adapter=html5mp4_download', "" , "html5mp4_download", "", "", "", ""),
    ] 

class JsLoader_VVBegin_Html5Mp4(Static):
    save = "jsloader_vv_Html5Mp4.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_Html5Mp4_VID.txt"
    urlReg = [
            (r'/statis/vv\?adapter=html5_mp4', "" , "html5mp4_error", "", "", "", ""),
    ] 

class JsLoader_VVBegin_NoAdapterParam(Static):
    save = "jsloader_vv_NoAdapterParam.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_NoAdapterParam.txt"
    urlReg = [
            (r'/statis/vv\?pid=', "" , "html5mp4_error", "", "", "", ""),
    ] 

class JsLoader_VVBegin_Flash(Static):
    save = "jsloader_vv_Flash.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_Flash.txt"
    urlReg = [
            (r'/statis/vv\?adapter=flash', "" , "html5mp4_error", "", "", "", ""),
    ] 


class JsLoader_VVBegin(Static):
    save = "jsloader_vv_begin.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=begin"
    vidFile = "JsLoader_VVBegin_VID.txt"
    urlReg = [
            (r'/statis/vv', "" , "JsLoader_VVBegin", "", "", "", ""),
    ] 


class WebApp_VVBegin(Static):
    save = "webapp_vv_begin.json"
    log = Static.statisLog
    pidFilter = "a4f46b4582fa09f3"
    paramFilter = "type=begin"
    vidFile = "WebApp_VVBegin_VID.txt"
    urlReg = [
            (r'/statis/vv', "" , "WebApp_VVBegin", "", "", "", ""),
    ] 
    

class JsLoader_VVEnd(Static):
    save = "jsloader_vv_end.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    paramFilter = "type=end"
    urlReg = [
            (r'/statis/vv', "" , "jsloader_vv_end", "", "", "", ""),
    ] 
  
class JsLoader_VV(Static):
    save = "jsloader_vv.json"
    log = Static.statisLog
    pidFilter = "2bd988a9275d4a61"
    urlReg = [
            (r'/statis/vv', "" , "jsloader_vv", "", "", "", ""),
    ] 
   
   
class Access(Static):
    save = "access.json"
    log = Static.accessLog
    urlReg = [
            (r'wireless/getRelated', "" , "related", "", "success", "", ""),
            (r'wireless/getVideoDetail', "" , "video_detail", "", "success", "", ""),
            (r'cms/ipad/getShowRecList', "" , "show_reclist", "", "success", "", ""),
            (r'cms/ipad/getShowTopList', "" , "show_toplist", "", "success", "", ""),
            (r'wireless/user/login', "" , "login", "", "success", "", ""),
            (r'wireless/user/favorites/add', "" , "fav_add", "", "success", "", ""),
            (r'wireless/user/favorites/del', "" , "fav_del", "", "success", "", ""),
                     
            (r'/phone2/main', "" , "phone_main", "", "success", "", ""),
            (r'/phone2_1/detail', "" , "phone_detail", "", "success", "", ""),
            (r'/ipad2_2/main', "" , "ipad_main", "", "success", "", ""),
            (r'/ipad2_2/desc', "" , "ipad_desc", "", "success", "", ""),
            (r'/playurl', "" , "playurl", "", "success", "", ""),
            (r'/search/', "" , "search", "", "success", "", ""),
            (r'/user/register', "" , "register", "register", "code200", "", ""),
            (r'/user/uploads/add', "" , "upload", "upload", "code200", "", "")
    ]
  

class All(Static):
    save = "all.json"
    log = Static.accessLog
    urlReg = [
            (r"all", "" , "all", "pv", "total", "uv", "total"),
    ]
  
    
class VV_Begin(Static):
    save = "vv_begin.json";
    log = Static.statisLog
    paramFilter = "type=begin"
    vidFile = "VVBegin_VID.txt"
    urlReg = [
#            (r"/statis/vv\.?(json|xml|text)?", "" , "vv", "vv", "total", "", "")
            (r"/statis/vv", "" , "vv_begin", "vv", "total", "", "")
    ]
    
class VV_End(Static):
    save = "vv_end.json";
    log = Static.statisLog
    paramFilter = "type=end"
    urlReg = [
            (r"/statis/vv", "" , "vv_end", "", "total", "", "")
    ]
    
class VV_NoBeginEnd(Static):
    save = "vv_nobeginend.json";
    log = Static.statisLog
    paramFilter = "!type=begin type=end"
    urlReg = [
            (r"/statis/vv", "" , "vv_nobegin_noend", "", "total", "", ""),
    ]        

class VV(Static):
    save = "vv.json";
    log = Static.statisLog
    urlReg = [
            (r"/statis/vv", "" , "vv", "", "total", "", "")
    ]   
   
class Initial(Static):
    save = "initial.json";
    log = Static.statisLog
    urlReg = [
          (r"/initial", "" , "initial", "", "code200", "", "")    
          ]

class InitialGuid(Static):
    save = "initial_guid.json";
    log = Static.statisLog
    paramFilter = "guid=[a-z0-9]{32}"
    urlReg = [
          (r"/initial", "" , "initial", "", "code200", "", "")    
          ]
        
class InitialNoGuid(Static):
    save = "initial_noguid.json";
    log = Static.statisLog
    paramFilter = "!guid=[a-z0-9]{32}"
    uniqueFields = "pid uuid"
    urlReg = [
          (r"/initial", "" , "initial", "", "code200", "", "")    
          ]    


def delTmpLog():
    cmd = "rm -fr " + Config.SaveLogDir + "*.tmplog" 
    print cmd
    result = os.popen(cmd)
    result = result.read()
    print result

def statist(stat, format="string", isSplit=True, logPath=""):
    
    print "-----statist-----"
    
    path = ""
    if(isSplit):    
        
        #不包括_nopid
        #path = stat.SaveLogDir + stat.date[0:4] + "/" + stat.date[4:6] + "/" + stat.date[6:8] + "/[0-9,a-z]*/" + stat.log + "_[0-9][0-9]"
        
            
        #包括_nopid nomatch
        path = stat.SaveLogDir + stat.date[0:4] + "/" + stat.date[4:6] + "/" + stat.date[6:8] + "/*/" + stat.log + "_[0-9][0-9]*"
        
       
            
    else:
        tmpPath = Config.SaveLogDir + stat.log + "_log_" + stat.date + "_sort.tmplog"
        if(not os.path.exists(tmpPath)):
            path = Config.SaveLogDir + stat.log + "_log_" + stat.date + "_sort.tar.gz -C " + Config.SaveLogDir
            cmd = "tar zxvf " + path 
            print cmd
            result = os.popen(cmd)
            result = result.read()
            print result
        
        
            cmd = "mv " + Config.SaveLogDir + stat.log + "_log_" + stat.date + "_sort " + tmpPath
            print cmd
            result = os.popen(cmd)
            result = result.read()
            print result
        
        path = tmpPath
      
    if(logPath != ""):
         path = logPath 
       
   
    apiFilter = ""
    paramFilter = ""
    for a, b, c, d, e, f, g in stat.urlReg:
        a = a.replace("\\", "\\\\") 
        apiFilter = apiFilter + a + " "
    apiFilter = apiFilter.lstrip().rstrip()
    paramFilter = stat.paramFilter
    
    if(apiFilter == ""):
        apiFilter = "all"
    
    if(paramFilter == ""):
        paramFilter = "any"
        
    
    print "path=" + path
    print "apiFilter=" + apiFilter
    print "paramFilter=" + paramFilter
    
    
    starttime = time.time()
    vidFile = ""
    if(stat.vidFile != ""):
        vidFile = Config.StatistResultsDir + stat.date + "/" + stat.vidFile 
    cmd = "cat " + path + " | " + Config.gawk + "  -v time='" + stat.date + "' -v vidFile='" + vidFile + "' -v notCheckGuidValidate='0' -v uniqueFields='" + stat.uniqueFields + "'  -v apiFilter='" + apiFilter + "'  -v paramFilter='" + paramFilter + "' -v pidFilter='" + stat.pidFilter + "' -v notStatistPid='" + notStatistPid + "' -f " + Config.ScriptsDir + "LogStatistV3.awk"
    print cmd  
    result = os.popen(cmd)
    result = result.read()
    endtime = time.time()
    print "Run times:" + str(int((endtime - starttime)))  
  
    if(stat.save is None):
        stat.save = ""
    else:
        stat.save = stat.save.lstrip().rstrip()
        
    if(stat.save != ""):  
        jsonDir = StatistResultsDir + stat.date;
        if(not os.path.exists(jsonDir)):
            os.makedirs(jsonDir)
        file = open(jsonDir + '/' + stat.save, 'w+')
        file.write(result)
        file.close()
        print os.path.realpath(file.name)
    
    
    print "\n"
    
    if(format == "json"):
        return json.loads(result)
    else:
        return result
    
 
def insert(stat, type="all"):    
    
    if(type == "all"):
        insert(stat, "main")
        insert(stat, "paike")
        insert(stat, "channel")
        insert(stat, "factory")
        insert(stat, "")
        return;
    
    
    table = "stat_day"
    if(type != ""):
        table = table + "_" + type 
    pidList = ""
    if(type == "main"):
        #nopid存储到主客户端表里
        pidList = getPid.getMainPid_json() 
        pidList = json.loads(pidList);
        pidList["results"].append("nopid")
        pidList = simplejson.dumps(pidList)
    elif(type == "paike"):
        pidList = getPid.getPaikePid_json()
    elif(type == "channel"):
        pidList = getPid.getChannelPid_json()  
    elif(type == "factory"):
        pidList = getPid.getFactoryPid_json()
    elif(type == ""):
        pidList = "{\"results\":\"noFiltPid\"}"
    
          
    pidList = simplejson.loads(pidList)
         
    jsonFile = StatistResultsDir + stat.date + "/" + stat.save
    print  "save " + os.path.realpath(jsonFile) + " to " + table
   
   
    if(not os.path.exists(jsonFile)):
        print jsonFile + " is not exists. can not save table:" + table + "\n"
        return
     
    jsonStr = open (jsonFile, 'r')  
    jsonStr = jsonStr.read()
    try:
        jsonStr = simplejson.loads(jsonStr)
    except:
        traceback.print_exc()
        print
        return
    pvResults = jsonStr["pvResults"]
    uvResults = jsonStr["uvResults"]
    
    
    try:
        conn = connectMySQL.connMySQL_stat()
    except:
        traceback.print_exc()
        print
        return
    
    cursor = conn.cursor()
    
    try:
        ver = "";
        
        if(type != ""):
            for pid in pidList["results"]:
                try:
                    sql = "insert into  " + table + "(pid,date,ver) values(%s,%s,%s)"
                    param = (pid, stat.date , ver)
                    cursor.execute(sql, param) 
                except:
                    pass
                finally:
                    pass
       
       
        for pv in pvResults:
            pid = pv["pid"]
            api = pv["api"]
            
            if(type == "main" and pid == "nopid"):
                try:
                    sql = "insert into  " + table + "(pid,date," + d + ",ver) values(%s,%s,%s,%s)"
                    param = (pid, stat.date , num, ver)
                    cursor.execute(sql, param) 
                except:
                    try:
                        sql = "update  " + table + " set " + d + "=%s where pid=%s and date=%s and ver=%s"
                        param = (num, pid, stat.date, ver)
                        cursor.execute(sql, param) 
                    except:
                        pass
                    finally:
                        pass
            
            if(not pid in pidList["results"] and pidList["results"] != "noFiltPid"):
                continue
    
            for a, b, c, d, e, f, g in stat.urlReg:
                if(api.find(a) != -1 and d != ""):
                    num = 0
                    if(e != "total"):
                        num = pv.get(e, 0)
                        num = num.get("num") if num else 0
                    else:
                        num = pv.get(e, 0)   
                        
                    if((table == "stat_day") or  (table != "stat_day" and d != "pv")):       
                        try:
                            sql = "insert into  " + table + "(pid,date," + d + ",ver) values(%s,%s,%s,%s)"
                            param = (pid, stat.date , num, ver)
                            cursor.execute(sql, param) 
                        except:
                            try:
                                sql = "update  " + table + " set " + d + "=%s where pid=%s and date=%s and ver=%s"
                                param = (num, pid, stat.date, ver)
                                cursor.execute(sql, param) 
                            except:
                                pass
                        finally:
                            pass
                    
                    
                    
        for result in uvResults:
            pid = result["pid"]
            api = result["api"]
            if(not pid in pidList["results"]  and pidList["results"] != "noFiltPid"):
                continue
    
            for a, b, c, d, e, f, g in stat.urlReg:
                if(api.find(a) != -1 and f != ""):
                    num = 0
                    if(g != "total"):
                        num = result.get(g, 0)
                        num = num.get("num") if num else 0
                    else:
                        num = result.get(g, 0)
                        
                    if((table == "stat_day") or  (table != "stat_day" and f != "uv")):             
                        try:
                            sql = "insert into  " + table + "(pid,date," + f + ",ver) values(%s,%s,%s,%s)"
                            param = (pid, stat.date , num, ver)
                            cursor.execute(sql, param) 
                        except:
                            try:
                                sql = "update  " + table + " set " + f + "=%s where pid=%s and date=%s and ver=%s"
                                param = (num, pid, stat.date, ver)
                                cursor.execute(sql, param)
                            except:
                                pass 
                        finally:
                            pass
    except:
        traceback.print_exc()
        print
    finally:
        conn.close()
    
def stat(statdate, isSplit=True, isSaveDB=True):
    
    vv_Begin = VV_Begin(statdate)
    vv = VV(statdate)
    vv_End = VV_End(statdate)
    vv_noBeginEnd = VV_NoBeginEnd(statdate)
   
    initial = Initial(statdate)
    initialGuid = InitialGuid(statdate)
    initialNoGuid = InitialNoGuid(statdate)
    
    access = Access(statdate)
    all = All(statdate)
    
    
   
    delTmpLog()
    
    
    jsloader = JsLoader_InitialUuid(statdate)
    statist(jsloader, isSplit=isSplit)  
    
    jsloader = JsLoader_Initial(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_InitialGuid(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_InitialNoGuid(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_VVDetail(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_VVBegin(statdate)
    statist(jsloader, isSplit=isSplit)  
     
    jsloader = JsLoader_VVEnd(statdate)
    statist(jsloader, isSplit=isSplit) 
      
    jsloader = JsLoader_VV(statdate)
    statist(jsloader, isSplit=isSplit)   
    
    jsloader = JsLoader_VVBegin_Html5Mp4Download(statdate)
    statist(jsloader, isSplit=isSplit) 
    
    jsloader = JsLoader_VVBegin_Html5Mp4Error(statdate)
    statist(jsloader, isSplit=isSplit) 
    
    jsloader = JsLoader_VVBegin_Html5Mp4(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_VVBegin_AndroidM3u8(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_VVBegin_iOSM3u8(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_VVBegin_NoAdapterParam(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_VVBegin_PlayurlError(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_VVBegin_PlayurlErrCode(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_VVBegin_PlayurlErrCode400(statdate)
    statist(jsloader, isSplit=isSplit)
    
    jsloader = JsLoader_VVBegin_Flash(statdate)
    statist(jsloader, isSplit=isSplit)
    
    webapp = WebApp_VVBegin(statdate)
    statist(webapp, isSplit=isSplit) 
         
    statist(vv_Begin, isSplit=isSplit)
#    statist(vv, isSplit=isSplit)
#    statist(vv_End, isSplit=isSplit)
    statist(vv_noBeginEnd, isSplit=isSplit)
   
       
    statist(initial, isSplit=isSplit)
#    statist(initialGuid, isSplit=isSplit)
#    statist(initialNoGuid, isSplit=isSplit)
        
    
    statist(access, isSplit=isSplit)
#    statist(all, isSplit=isSplit)

    
   
    delTmpLog()

        
    if(isSaveDB):
        print "-----statist save DB-----"   
        starttime = time.time()
        try: 
            insert(vv_Begin, "all")
        except:
            traceback.print_exc()
            print
        
        try:
            insert(access, "all")
        except:
            traceback.print_exc()
            print
        
        try:
            insert(all, "all")
        except:
            traceback.print_exc()
            print
        
        endtime = time.time()
        print "-----statist save DB Run times:" + str(int((endtime - starttime))) + "-----\n"
      
        
if __name__ == "__main__":
    argv = sys.argv
    statdate = argv[1]
    
    isSplit = True
    try:
        argv2 = argv[2]
        if(str(argv2) == "sort"):
            isSplit = False
    except:
        isSplit = True 
        
        
    try:
        argv3 = argv[3]
        if(str(argv3) == "noSaveDB"):
            isSaveDB = False
    except:
        isSaveDB = True
    
    stat(statdate=statdate, isSplit=isSplit, isSaveDB=isSaveDB)
    
